package com.budwk.app.sqfw.services.customservice;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.common.config.AppException;
import com.budwk.app.exception.Asserts;
import com.budwk.app.oss.services.SysOssService;
import com.budwk.app.sqfw.component.CommunityStreetComponent;
import com.budwk.app.sqfw.constants.CommonConstants;
import com.budwk.app.sqfw.constants.CommonForAdminConstants;
import com.budwk.app.sqfw.constants.SqfwFormSummaryConstants;
import com.budwk.app.sqfw.dto.StatisticParamDTO;
import com.budwk.app.sqfw.enums.SupportBusinessTypeEnum;
import com.budwk.app.sqfw.models.Sqfw_completeflow;
import com.budwk.app.sqfw.models.Sqfw_formSummary;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.models.Sqfw_form_summary_pdf;
import com.budwk.app.sqfw.services.SqfwCompleteflowService;
import com.budwk.app.sqfw.services.SqfwFormSummaryPdfService;
import com.budwk.app.sqfw.services.SqfwFormsummaryNewService;
import com.budwk.app.sqfw.services.common.SqfwCustomForAdminCommonService;
import com.budwk.app.sqfw.vo.CheckDataForAdminVO;
import com.budwk.app.sqfw.vo.GenerateExcelUrlVO;
import com.budwk.app.sqfw.vo.GenerateWordAndPdfUrlVO;
import com.budwk.app.sqfw.vo.SqfwCustomForAdminCommonVO;
import com.budwk.app.sqfwDoc.bo.ExcelCreateConfig;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseExcelParamDTO;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseTemplateExcelGenerator;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.ExcelGeneratorConfig;
import com.budwk.app.sqfwV2.component.centuryCity.CenturyCitySecurityExcelService;
import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckGasDTO;
import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckTaskPdfDTO;
import com.budwk.app.sqfwV2.enums.*;
import com.budwk.app.sqfwV2.enums.jinYang.JinYangExcelEnum;
import com.budwk.app.sqfwV2.generator.binyangStreet.excel.CampusTrainingOffExcel;
import com.budwk.app.sqfwV2.generator.binyangStreet.excel.EnterpriseSafetyInvestigationExcel;
import com.budwk.app.sqfwV2.generator.binyangStreet.excel.LargeCompanySafeGenerator;
import com.budwk.app.sqfwV2.generator.binyangStreet.excel.logisticsWarehouseExcelGenerator;
import com.budwk.app.sqfwV2.generator.yuHong.BackPayGenerator;
import com.budwk.app.sqfwV2.service.CenturyCitySecurityService;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysLogService;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.util.adminUtils.CommonCheckUtils;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.ResultCode;
import com.budwk.starter.security.utils.SecurityUtil;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Cnd;
import org.nutz.dao.Sqls;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.dao.sql.Criteria;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.dao.util.cri.Static;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

/**
 * @program: dfxy-community
 * @description: 世纪城安全巡查服务实现（后台管理系统）
 * @author: LJT
 * @create: 2024-02-18 16:23
 **/
@IocBean(name = "CenturyCitySecurityForAdminService")
@Slf4j
public class CenturyCitySecurityForAdminServiceImpl extends CenturyCitySecurityExcelService implements SqfwCustomForAdminCommonService {

    private final Map<String, String> mapFileIndex = new ConcurrentHashMap<>();

    @Inject
    SysUserService sysUserService1;

    @Inject
    private SqfwFormsummaryNewService sqfwFormsummaryNewService1;

    @Inject
    private CommunityStreetComponent communityStreetComponent;

    @Inject
    private SqfwCompleteflowService sqfwCompleteflowService;

    @Inject
    private CenturyCitySecurityService centuryCitySecurityService;

    @Inject
    private SysLogService sysLogService;

    @Inject
    private SqfwFormSummaryPdfService formSummaryPdfService;

    @Inject
    private SysOssService sysOssService;

    private static final String CENTURY_CITY = "世纪城街道";

    private StatisticParamDTO statisticParamDTO = new StatisticParamDTO();

    @Override
    public Pagination list(SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        long startTime = System.currentTimeMillis();
        // 构造查询条件
        Criteria criteria = buildQueryCond(bean);
        log.info("SqfwCustomForAdminCommonServiceImpl-list-SQL: {}", criteria.toString());
        Pagination pagination = sqfwFormsummaryNewService1.listPage(bean.getPageNo(), bean.getPageSize(), criteria);
        // 查询流程pdf
        List<Sqfw_formSummary_new> sqfwCustomForAdminCommonVOList = pagination.getList(Sqfw_formSummary_new.class);
        if (ObjectUtil.isNotEmpty(sqfwCustomForAdminCommonVOList)) {
            List<SqfwCustomForAdminCommonVO> finalCommonVOList = new ArrayList<SqfwCustomForAdminCommonVO>();
            Map<String, String> pdfUrlMap = CommonCheckUtils.getPdfUrlByFlowId(sqfwCustomForAdminCommonVOList);
            sqfwCustomForAdminCommonVOList.forEach(source -> {
                SqfwCustomForAdminCommonVO target = new SqfwCustomForAdminCommonVO();
                BeanUtil.copyProperties(source, target);
                target.setPdfUrl(pdfUrlMap.get(target.getSqfwFlowId()));
                target.setStatisticParam(statisticParamDTO);
                finalCommonVOList.add(target);
            });
            pagination.setList(finalCommonVOList);
        }
        log.info("SqfwCustomForAdminCommonServiceImpl-list-耗时: {}ms", System.currentTimeMillis() - startTime);
        return pagination;
    }

    @Override
    @Aop(TransAop.READ_COMMITTED)
    public int delete(String id) {
        int num = 0;
        Sqfw_formSummary_new sqfwFormsummaryNew = sqfwFormsummaryNewService1.fetch(id);
        if (sqfwFormsummaryNew == null) {
            return num;
        }
        log.info("删除记录:{},{}", SecurityUtil.getUserId(), id);
        sqfwCompleteflowService.deleteAndUpdateWO(sqfwFormsummaryNew.getSqfwFlowId());
        return num;
    }

    @Override
    @Aop(TransAop.READ_COMMITTED)
    public int batchDelete(List<String> ids) {
        if (ids == null || ids.size() == 0) {
            throw new AppException(ResultCode.NULL_DATA_ERROR.getMsg());
        }
        // 查询数据
        Cnd cnd = Cnd.NEW();
        cnd.and(Sqfw_formSummary::getId, "in", ids);
        List<Sqfw_formSummary_new> newList = sqfwFormsummaryNewService1.query(cnd);
        if (newList.isEmpty()) {
            throw new AppException(ResultCode.NULL_DATA_ERROR.getMsg());
        }
        String userId = SecurityUtil.getUserId();
        // 异步执行删除操作
        if (!newList.isEmpty()) {
            ExecutorService executorService = Executors.newSingleThreadExecutor();
            try {
                CompletableFuture.runAsync(() -> {
                    for (Sqfw_formSummary_new sqfwFormSummaryNew : newList) {
                        batchDeleteDataNew(userId, sqfwFormSummaryNew);
                    }
                }, executorService).join();
            } catch (Exception ex) {
                log.info(ex.getMessage());
            } finally {
                executorService.shutdown();
            }
        }
        return newList.size();
    }

    @Override
    @Aop(TransAop.READ_COMMITTED)
    public int update(Sqfw_formSummary_new sqfwFormsummaryNew) {
        sqfwFormsummaryNew.setUpdateBy(SecurityUtil.getUserId());
        sqfwFormsummaryNew.setUpdateDate(new Date());
        return sqfwFormsummaryNewService1.updateIgnoreNull(sqfwFormsummaryNew);
    }

    @Override
    public List<GenerateExcelUrlVO> downloadExcel(List<ExcelCreateConfig> excelConfigList, SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        mapFileIndex.put(SecurityUtil.getUserId(), excelConfigList.get(0).getFileIdentity());
        if (excelConfigList.get(0).getOnlyGenerateTemplateFlag() == true) {
            bean.setFormSummaryNewIdList(Collections.emptyList());
            return super.generateExcelForAdmin(excelConfigList, SecurityUtil.getUserId(), bean.getFormSummaryNewIdList());
        }
        // 如果formSummaryNewIdList为空，根据条件下载，否则根据勾选id下载
        if (ObjectUtil.isEmpty(bean.getFormSummaryNewIdList()) || bean.getFormSummaryNewIdList().size() <= 0) {
            Criteria criteria = buildQueryCond(bean);
            List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService1.query(criteria);
            if (summaryNewList.size() > 0) {
                bean.setFormSummaryNewIdList(sqfwFormsummaryNewService1.query(criteria).stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
            } else {
                return new ArrayList<GenerateExcelUrlVO>();
            }
        } else {
            Cnd cnd = Cnd.NEW();
            // 时间
            if (ObjectUtil.isNotEmpty(bean.getQueryStartTime()) && ObjectUtil.isNotEmpty(bean.getQueryEndTime())) {
                cnd.and(Sqfw_formSummary_new::getFillDate, ">=", communityStreetComponent.handleStartQueryTime(bean.getQueryStartTime()));
                cnd.and(Sqfw_formSummary_new::getFillDate, "<=", communityStreetComponent.handleEndQueryTime(bean.getQueryEndTime()));
            }
            cnd.and(Sqfw_formSummary_new::getId, "IN", bean.getFormSummaryNewIdList());
            List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService1.query(cnd);
            if (summaryNewList.size() > 0) {
                bean.setFormSummaryNewIdList(summaryNewList.stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
            } else {
                return new ArrayList<GenerateExcelUrlVO>();
            }
        }
        return super.generateExcelForAdmin(excelConfigList, SecurityUtil.getUserId(), bean.getFormSummaryNewIdList());
    }

    @Override
    protected List<Sqfw_formSummary_new> queryForSummaryDataForAdmin(List<String> ids) {
        String fileIndex = mapFileIndex.get(SecurityUtil.getUserId());
        String type = CenturyCitySafeServiceEnum.getType(fileIndex);
        if (YuHongEnum.BACK_PAY.getCode().equals(fileIndex)) {
            type = YuHongEnum.BACK_PAY.getType();
        }
        // 宾阳街道
        if (StringUtils.isEmpty(type)) {
            // 去宾阳街道获取
            BinYangFileServiceEnum serviceEnum = BinYangFileServiceEnum.getByCode(fileIndex);
            if (serviceEnum != null) {
                return queryBySqfwIdsAndType(ids, SupportBusinessTypeEnum.SAFE_CHECK.getName());
            }
        }
        //金阳 新增excel
        JinYangExcelEnum jinYangEnum = JinYangExcelEnum.getJinYangEnum(fileIndex);
        if (ObjectUtils.isNotEmpty(jinYangEnum)) {
            //是否走原来基础类的处理方式
            if (!jinYangEnum.isUseOriginalMethod()) {
                //新增的excel数据查询方式不一样
                return queryJinYangGasUse(ids, SupportBusinessTypeEnum.SAFE_CHECK.getName());
            } else {
                type = jinYangEnum.getType();
            }
        }
        if (ids.size() == 0) return Collections.emptyList();
        String sqfwFormSummaryType = getSqfwFormSummaryType();
        if (org.apache.commons.lang3.StringUtils.isBlank(sqfwFormSummaryType)) Asserts.fail("forSummary类型不能为空");
        Cnd cnd = Cnd.NEW();
        cnd.and("id", "in", ids).and("type", "=", sqfwFormSummaryType);
        cnd.and("param_data ->> 'type'", "in", "'" + type + "'");
        if (CenturyCitySafeServiceEnum.CENTER_CITY_FOOD_SAFE.getCode().equals(fileIndex)) {
//            cnd.and("param_data ->> 'placeType'", "in",
//                    Arrays.asList(CenturyCitySafePlaceTypeEnum.RESTAURANT.getName(), CenturyCitySafePlaceTypeEnum.SHOP.getName()));
            cnd.and("param_data->>'fileOutputType'", "<>", "[\"-1\"]");
        }
        cnd.orderBy("fill_date", "asc");
        List<Sqfw_formSummary_new> sqfwFormSummaryNewS = sqfwFormsummaryNewService1.query(cnd);
        List<Sqfw_formSummary_new> sqfwFormSummaryNewList = new ArrayList<Sqfw_formSummary_new>();
        if (YuHongEnum.BACK_PAY.getCode().equals(fileIndex)) {
            sqfwFormSummaryNewList = sqfwFormSummaryNewS;
        } else {
            //燃气不需要在这里构建参数
            if (!CenturyCitySafeServiceEnum.CENTER_CITY_GAS_SAFE.getCode().equals(fileIndex)) {
                sqfwFormSummaryNewList = buildFormSummaryParam(sqfwFormSummaryNewS, type, fileIndex, "WEB");
            } else {
                //燃气
                sqfwFormSummaryNewList = buildGasFormSummaryParam(sqfwFormSummaryNewS);
            }
        }
        mapFileIndex.remove(SecurityUtil.getUserId());
        return sqfwFormSummaryNewList;
    }

    @Override
    public GenerateWordAndPdfUrlVO downloadPdf(List<ExcelCreateConfig> excelConfigList, SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        GenerateWordAndPdfUrlVO generateWordAndPdfUrlVO = new GenerateWordAndPdfUrlVO();
        String fileIndentity = excelConfigList.get(0).getFileIdentity();
        if (excelConfigList.get(0).getOnlyGenerateTemplateFlag()) {
            String filePath = "";
            String fileName = "";
            BinYangFileServiceEnum binYangFileServiceEnum = BinYangFileServiceEnum.getByCode(fileIndentity);
            if (null != binYangFileServiceEnum) {
                filePath = binYangFileServiceEnum.getTemplatePath();
                if (filePath.endsWith("docx")) {
                    fileName = binYangFileServiceEnum.getFileName() + ".docx";
                } else {
                    fileName = binYangFileServiceEnum.getFileName() + ".xlsx";
                }
            } else {
                filePath = SafetyCheckV2Enums.getUrl(Integer.valueOf(fileIndentity));
                fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            }
            generateWordAndPdfUrlVO.setPdfUrl(sysOssService.upload(CommonFormOfficeUtils.getTempPdfFile(filePath), fileName).getUrl());
        } else {
            // 如果formSummaryNewIdList为空，根据条件下载，否则根据勾选id下载
            if (ObjectUtil.isEmpty(bean.getFormSummaryNewIdList()) || bean.getFormSummaryNewIdList().size() <= 0) {
                Criteria criteria = buildQueryCond(bean);
                List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService1.query(criteria);
                if (summaryNewList.size() > 0) {
                    bean.setFormSummaryNewIdList(sqfwFormsummaryNewService1.query(criteria).stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
                } else {
                    return new GenerateWordAndPdfUrlVO();
                }
            } else {
                Cnd cnd = Cnd.NEW();
                // 时间
                if (ObjectUtil.isNotEmpty(bean.getQueryStartTime()) && ObjectUtil.isNotEmpty(bean.getQueryEndTime())) {
                    cnd.and(Sqfw_formSummary_new::getFillDate, ">=", communityStreetComponent.handleStartQueryTime(bean.getQueryStartTime()));
                    cnd.and(Sqfw_formSummary_new::getFillDate, "<=", communityStreetComponent.handleEndQueryTime(bean.getQueryEndTime()));
                }
                cnd.and(Sqfw_formSummary_new::getId, "IN", bean.getFormSummaryNewIdList());
                List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService1.query(cnd);
                if (summaryNewList.size() > 0) {
                    bean.setFormSummaryNewIdList(summaryNewList.stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
                } else {
                    return new GenerateWordAndPdfUrlVO();
                }
            }
            boolean isMultiple = false;
            Cnd cnd = Cnd.NEW();
            if (fileIndentity.equals(BinYangFileServiceEnum.ONE_PDF.getCode())) {
                cnd.and(" param_data->>'type'", "=", BinYangFileServiceEnum.ONE_PDF.getLabel());
            } else if (fileIndentity.equals(BinYangFileServiceEnum.TWO_PDF.getCode())) {
                cnd.and(" param_data->>'type'", "=", BinYangFileServiceEnum.TWO_PDF.getLabel());
            } else if (fileIndentity.equals(BinYangFileServiceEnum.THREE_PDF.getCode())) {
                cnd.and(" param_data->>'type'", "=", BinYangFileServiceEnum.THREE_PDF.getLabel());
            } else if (fileIndentity.equals(BinYangFileServiceEnum.FORE_PDF.getCode())) {
                cnd.and(" param_data->>'type'", "=", BinYangFileServiceEnum.FORE_PDF.getLabel());
            } else {
                cnd.and(" param_data->>'type'", "=", SafetyCheckV2Enums.getName(Integer.valueOf(fileIndentity)));
            }
            /* if (fileIndentity.equals(String.valueOf(SafetyCheckV2Enums.G.getCode()))
                    || fileIndentity.equals(String.valueOf(SafetyCheckV2Enums.K.getCode()))) {
                cnd.and("param_data ->> 'placeType'", "in",
                        Arrays.asList(CenturyCitySafePlaceTypeEnum.RESTAURANT.getName(), CenturyCitySafePlaceTypeEnum.SHOP.getName()));
                isMultiple = true;
            }*/
            Set<String> isMultipleSet = Sets.newHashSet(String.valueOf(SafetyCheckV2Enums.A.getCode()), String.valueOf(SafetyCheckV2Enums.C.getCode())
                    , String.valueOf(SafetyCheckV2Enums.G.getCode()), String.valueOf(SafetyCheckV2Enums.K.getCode()), String.valueOf(SafetyCheckV2Enums.L.getCode()));
            //修改，只要包含一个就是多文件
            if (isMultipleSet.contains(excelConfigList.get(0).getFileIdentity())) {
                isMultiple = true;
            }
            cnd.and(Sqfw_formSummary_new::getType, "=", SupportBusinessTypeEnum.SAFE_CHECK.getName());
            cnd.and(Sqfw_formSummary_new::getId, "in", bean.getFormSummaryNewIdList());
            cnd.desc(Sqfw_formSummary_new::getFillDate);
            List<Sqfw_formSummary_new> sqfwFormSummaryNews = sqfwFormsummaryNewService1.query(cnd);
            if (CollectionUtil.isNotEmpty(sqfwFormSummaryNews)) {
                if (isMultiple) {
                    //zhangp 2024-03-06 九小场所-餐饮走这个
                    List<String> SummaryIdS = sqfwFormSummaryNews.stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList());
                    List<Sqfw_form_summary_pdf> sqfwFormSummaryPdfs = formSummaryPdfService.query(Cnd.where(Sqfw_form_summary_pdf::getSummaryId, "in", SummaryIdS)
                            .and(Sqfw_form_summary_pdf::getIndex, "=", fileIndentity)
                            .and(Sqfw_form_summary_pdf::getStatus, "=", "2")
                            .asc(Sqfw_form_summary_pdf::getCreateDate));
                    if (!sqfwFormSummaryPdfs.isEmpty()) {
                        List<String> pdfPathList = sqfwFormSummaryPdfs.stream().map(Sqfw_form_summary_pdf::getUrl).collect(Collectors.toList());
                        String url = "";
                        if (fileIndentity.equals(BinYangFileServiceEnum.ONE_PDF.getCode())) {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, BinYangFileServiceEnum.ONE_PDF.getName());
                        } else if (fileIndentity.equals(BinYangFileServiceEnum.TWO_PDF.getCode())) {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, BinYangFileServiceEnum.TWO_PDF.getName());
                        } else if (fileIndentity.equals(BinYangFileServiceEnum.THREE_PDF.getCode())) {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, BinYangFileServiceEnum.THREE_PDF.getName());
                        } else if (fileIndentity.equals(BinYangFileServiceEnum.FORE_PDF.getCode())) {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, BinYangFileServiceEnum.FORE_PDF.getName());
                        } else {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, SafetyCheckV2Enums.getmergePdf(Integer.valueOf(fileIndentity)));
                        }
                        generateWordAndPdfUrlVO.setPdfUrl(url);
                    }
                } else {
                    List<String> sqfwFlowIdList = sqfwFormSummaryNews.stream().map(Sqfw_formSummary_new::getSqfwFlowId).collect(Collectors.toList());
                    List<Sqfw_completeflow> flwoList = sqfwCompleteflowService.query(Cnd.where(Sqfw_completeflow::getId, "in", sqfwFlowIdList)
                            .and(Sqfw_completeflow::getFileType, "LIKE", "%" + SqfwFormSummaryConstants.safety_check + "%")
                            .and(Sqfw_completeflow::getResourcePath, "!=", "creating")
                            .and(Sqfw_completeflow::getResourcePath, "!=", "error"));
                    if (!flwoList.isEmpty()) {
                        List<String> pdfPathList = flwoList.stream().map(Sqfw_completeflow::getResourcePath).collect(Collectors.toList());
                        String url = "";
                        if (fileIndentity.equals(BinYangFileServiceEnum.ONE_PDF.getCode())) {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, BinYangFileServiceEnum.ONE_PDF.getName());
                        } else if (fileIndentity.equals(BinYangFileServiceEnum.TWO_PDF.getCode())) {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, BinYangFileServiceEnum.TWO_PDF.getName());
                        } else if (fileIndentity.equals(BinYangFileServiceEnum.THREE_PDF.getCode())) {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, BinYangFileServiceEnum.THREE_PDF.getName());
                        } else if (fileIndentity.equals(BinYangFileServiceEnum.FORE_PDF.getCode())) {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, BinYangFileServiceEnum.FORE_PDF.getName());
                        } else {
                            url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, SafetyCheckV2Enums.getmergePdf(Integer.valueOf(fileIndentity)));
                        }
                        generateWordAndPdfUrlVO.setPdfUrl(url);
                    }
                }
            }
        }
        return generateWordAndPdfUrlVO;
    }

    @Override
    public List<GenerateExcelUrlVO> downloadPdfList(List<ExcelCreateConfig> excelConfigList, SqfwCustomForAdminCommonVO bean) {
        return null;
    }

    @Override
    public Criteria buildQueryCond(SqfwCustomForAdminCommonVO bean) {
        Criteria cri = Cnd.cri();
        SqlExpressionGroup criSql = cri.where();

        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        // 组装查询条件
        if (StringUtils.isNotBlank(bean.getPageOrderName()) && Strings.isNotBlank(bean.getPageOrderBy())) {
            if (bean.getPageOrderBy().equals(CommonConstants.ASC)) {
                cri.getOrderBy().asc(bean.getPageOrderName());
            }
            if (bean.getPageOrderBy().equals(CommonConstants.DESC)) {
                cri.getOrderBy().desc(bean.getPageOrderName());
            }
        } else {
            cri.getOrderBy().desc(Sqfw_formSummary_new::getFillDate);
        }
        // 类型
        criSql.andEquals(SqfwCustomForAdminCommonVO::getType, bean.getType());

        Sys_user sysUser = sysUserService1.fetch(SecurityUtil.getUserId());
        if (ObjectUtils.isEmpty(sysUser)) {
            throw new AppException(ResultCode.USER_NOT_FOUND.getMsg());
        }
        // 区域5级检查
        CommonCheckUtils.checkAreaRange(criSql);
        // 省
        if (StringUtils.isNotBlank(bean.getProvince()) && !CommonCheckUtils.ZHISHU.equals(bean.getProvince())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getProvince, bean.getProvince());
        }
        // 市
        if (StringUtils.isNotBlank(bean.getCity()) && !CommonCheckUtils.ZHISHU.equals(bean.getCity())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getCity, bean.getCity());
        }
        // 区
        if (StringUtils.isNotBlank(bean.getDistrict()) && !CommonCheckUtils.ZHISHU.equals(bean.getDistrict())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getDistrict, bean.getDistrict());
        }
        // 街道
        if (StringUtils.isNotBlank(bean.getCounty()) && !CommonCheckUtils.ZHISHU.equals(bean.getCounty())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getCounty, bean.getCounty());
        }
        // 时间
        if (ObjectUtil.isNotEmpty(bean.getQueryStartTime()) && ObjectUtil.isNotEmpty(bean.getQueryEndTime())) {
            criSql.andBetween(Sqfw_formSummary_new::getFillDate,
                    communityStreetComponent.handleStartQueryTime(bean.getQueryStartTime()),
                    communityStreetComponent.handleEndQueryTime(bean.getQueryEndTime()));
        }
        // 辖区
        if (StringUtils.isNotBlank(bean.getCommunity()) && !CommonCheckUtils.ZHISHU.equals(bean.getCommunity())) {
            criSql.andEquals(Sqfw_formSummary_new::getCommunity, bean.getCommunity());
        }
        // 全局搜索
        if (StringUtils.isNotEmpty(bean.getQueryAll())) {
            SqlExpressionGroup placeName = Cnd.exps(new Static("param_data->>'placeName' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup siteManager = Cnd.exps(new Static("param_data->>'siteManager' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup operatorTelephone = Cnd.exps(new Static("param_data->>'operatorTelephone' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup type = Cnd.exps(new Static("param_data->>'type' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup typePlace = Cnd.exps(new Static("param_data->>'typePlace' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup county = Cnd.exps(new Static("county like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup community = Cnd.exps(new Static("community like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup createUserName = Cnd.exps(new Static("create_user_name like '%" + bean.getQueryAll() + "%'"));
            criSql.and(placeName.or(siteManager).or(operatorTelephone).or(type).or(typePlace).or(county).or(community).or(createUserName));
        }
        // 需要排除的数据
        criSql.andNotEquals(Sqfw_formSummary_new::getFillDate, CommonConstants.WASTE_CREATE_TIME);
        // 场所名称
        if (StringUtils.isNotBlank(bean.getPlaceName())) {
            criSql.andEquals("param_data->>'placeName'", bean.getPlaceName());
        }
        // 现场管理人员
        if (StringUtils.isNotBlank(bean.getSiteManager())) {
            criSql.andEquals("param_data->>'siteManager'", bean.getSiteManager());
        }
        // 经营者联系电话
        if (ObjectUtil.isNotEmpty(bean.getOperatorTelephone())) {
            criSql.andEquals("param_data->>'operatorTelephone'", bean.getOperatorTelephone());
        }
        // 检查人员
        if (ObjectUtil.isNotEmpty(bean.getCreateUserName())) {
            criSql.andEquals(Sqfw_formSummary_new::getCreateUserName, bean.getCreateUserName());
        }
        // 场所分类
        if (ObjectUtil.isNotEmpty(bean.getPlaceClassify())) {
            criSql.andEquals("param_data->>'type'", bean.getPlaceClassify());
        }
        // 场所类型
        if (ObjectUtil.isNotEmpty(bean.getPlaceType())) {
            criSql.andEquals("param_data->>'placeType'", bean.getPlaceType());
        }
        // 场所经营范围
        if (ObjectUtil.isNotEmpty(bean.getMainBusinessScope())) {
            criSql.andEquals("param_data->>'mainBusinessScope'", bean.getMainBusinessScope());
        }
        // 存在隐患
        if (StringUtils.isNotEmpty(bean.getIssueStatus())) {
            criSql.andEquals(Sqfw_formSummary_new::getIssueStatus, bean.getIssueStatus());
        }
        // 从数据统计页面跳转过来查询隐患次数
        if (ObjectUtil.isNotEmpty(bean.getStatisticParam()) && bean.getStatisticParam().getStatisticFlag() && org.apache.commons.lang3.StringUtils.isNotEmpty(bean.getStatisticParam().getTimeType())) {
            statisticParamDTO = new StatisticParamDTO();
            statisticParamDTO = CommonCheckUtils.statisticTimeSectionByType(bean.getStatisticParam().getTimeType());
            // 时间
            if (ObjectUtil.isNotEmpty(statisticParamDTO.getStartTime()) && ObjectUtil.isNotEmpty(statisticParamDTO.getEndTime())) {
                criSql.andBetween(Sqfw_formSummary_new::getFillDate, statisticParamDTO.getStartTime(), statisticParamDTO.getEndTime());
            }
        }
        // 增加查询限制条件
        if (StringUtils.isNotEmpty(bean.getQueryFlag()) && "1".equals(bean.getQueryFlag())) {
            criSql.andNotEquals(Sqfw_formSummary_new::getCounty, CommonForAdminConstants.areaInfoEnum.SHIJICHENG_STREET);
            criSql.andNotEquals(Sqfw_formSummary_new::getCounty, CommonForAdminConstants.areaInfoEnum.GUANSHAN_STREET);
            criSql.andNotEquals(Sqfw_formSummary_new::getCounty, CommonForAdminConstants.areaInfoEnum.BINYANG_STREET);
            criSql.andNotEquals(Sqfw_formSummary_new::getCounty, CommonForAdminConstants.areaInfoEnum.YUNTAN_STREET);
        }
        // 网格/小区
        if (StringUtils.isNotEmpty(bean.getPlotCode())) {
            criSql.andEquals("param_data->>'plotCode'", bean.getPlotCode());
        }
        // 网格/小区
        if (StringUtils.isNotEmpty(bean.getPlot())) {
            criSql.andEquals("param_data->>'plot'", bean.getPlot());
        }
        return cri;
    }

    @Override
    public List<CheckDataForAdminVO> checkDataInfoList(SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        List<Sqfw_formSummary_new> summaryNewList = new ArrayList<Sqfw_formSummary_new>();
        // 如果formSummaryNewIdList为空，根据条件下载，否则根据勾选id下载
        if (ObjectUtil.isEmpty(bean.getFormSummaryNewIdList()) || bean.getFormSummaryNewIdList().size() <= 0) {
            Criteria criteria = buildQueryCond(bean);
            summaryNewList = sqfwFormsummaryNewService1.query(criteria);
            if (summaryNewList.size() <= 0) {
                return new ArrayList<CheckDataForAdminVO>();
            }
        } else {
            Cnd cnd = Cnd.NEW();
            // 时间
            if (ObjectUtil.isNotEmpty(bean.getQueryStartTime()) && ObjectUtil.isNotEmpty(bean.getQueryEndTime())) {
                cnd.and(Sqfw_formSummary_new::getFillDate, ">=", communityStreetComponent.handleStartQueryTime(bean.getQueryStartTime()));
                cnd.and(Sqfw_formSummary_new::getFillDate, "<=", communityStreetComponent.handleEndQueryTime(bean.getQueryEndTime()));
            }
            cnd.and(Sqfw_formSummary_new::getId, "IN", bean.getFormSummaryNewIdList());
            summaryNewList = sqfwFormsummaryNewService1.query(cnd);
            if (summaryNewList.size() <= 0) {
                return new ArrayList<CheckDataForAdminVO>();
            }
        }
        bean.setFormSummaryNewIdList(summaryNewList.stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
        List<CheckDataForAdminVO> checkDataForAdminVOList = new ArrayList<CheckDataForAdminVO>();

        List<String> typeList = summaryNewList.stream().map(m -> JSONObject.parseObject(m.getParamData(), SafeCheckTaskPdfDTO.class).getType()).distinct().collect(Collectors.toList());

        for (CenturyCitySafeServiceEnum item : CenturyCitySafeServiceEnum.values()) {
            CheckDataForAdminVO checkDataForAdminVO = new CheckDataForAdminVO();
            //excel
            checkDataForAdminVO.setType(item.getType());
            checkDataForAdminVO.setFileIdentity(item.getCode());
            checkDataForAdminVO.setFileName(CenturyCitySafeServiceEnum.getFileName(item.getCode()) + ".xlsx");
            checkDataForAdminVO.setCreateConditionFlag(false);
            checkDataForAdminVO.setLabel(Arrays.asList(CenturyCitySafeServiceEnum.getLabel(item.getCode()).split("\\|")));
            checkDataForAdminVOList.add(checkDataForAdminVO);
        }

        for (SafetyCheckV2Enums item : SafetyCheckV2Enums.values()) {
            CheckDataForAdminVO checkDataForAdminVO = new CheckDataForAdminVO();
            //pdf
            checkDataForAdminVO = new CheckDataForAdminVO();
            checkDataForAdminVO.setType(item.getName());
            checkDataForAdminVO.setFileIdentity(String.valueOf(item.getCode()));
            checkDataForAdminVO.setFileName(item.getMergePdf() + ".pdf");
            checkDataForAdminVO.setCreateConditionFlag(false);
            checkDataForAdminVO.setLabel(Arrays.asList(SafetyCheckV2Enums.getLabel(String.valueOf(item.getCode())).split("\\|")));
            checkDataForAdminVOList.add(checkDataForAdminVO);
        }

        // 增加宇虹社区欠薪风险表
        for (YuHongEnum item : YuHongEnum.values()) {
            CheckDataForAdminVO checkDataForAdminVO = new CheckDataForAdminVO();
            checkDataForAdminVO = new CheckDataForAdminVO();
            checkDataForAdminVO.setType(item.getType());
            checkDataForAdminVO.setFileIdentity(String.valueOf(item.getCode()));
            checkDataForAdminVO.setFileName(item.getFileName() + ".xlsx");
            checkDataForAdminVO.setCreateConditionFlag(false);
            checkDataForAdminVO.setLabel(Arrays.asList(YuHongEnum.getLabel(String.valueOf(item.getCode())).split("\\|")));
            checkDataForAdminVOList.add(checkDataForAdminVO);
        }

        for (CheckDataForAdminVO item : checkDataForAdminVOList) {
            CheckDataForAdminVO checkDataForAdmin = new CheckDataForAdminVO();
            if (typeList.contains(item.getType())) {
                if (item.getFileIdentity().equals(CenturyCitySafeServiceEnum.CENTER_CITY_FOOD_SAFE.getCode())
                        || item.getFileIdentity().equals(String.valueOf(SafetyCheckV2Enums.G.getCode()))
                        || item.getFileIdentity().equals(String.valueOf(SafetyCheckV2Enums.K.getCode()))) {
                    Cnd c = Cnd.NEW();
                    c.and("id", "in", bean.getFormSummaryNewIdList()).and("type", "=", SupportBusinessTypeEnum.SAFE_CHECK.getName());
//                    c.and("param_data ->> 'placeType'", "in",
//                            Arrays.asList(CenturyCitySafePlaceTypeEnum.RESTAURANT.getName(), CenturyCitySafePlaceTypeEnum.SHOP.getName()));
                    c.and("param_data->>'fileOutputType'", "<>", "[\"-1\"]");
                    c.and("param_data ->>'type'", "=", CenturyCitySafeServiceEnum.CENTER_CITY_FOOD_SAFE.getType());
                    c.and(Cnd.exps("param_data ->>'transferToMarketSupervisionAndManagement'", "=", "是").or("param_data ->>'transferToMarketSupervisionAndManagement'", "=", "否"));
                    c.orderBy("create_date", "asc");
                    if (!item.getFileIdentity().contains(CenturyCitySafeServiceEnum.CENTER_CITY_NINE_SMALL_PLACE.getCode())
                            && !item.getFileIdentity().equals(String.valueOf(SafetyCheckV2Enums.G.getCode()))
                            && !item.getFileIdentity().equals(String.valueOf(SafetyCheckV2Enums.K.getCode()))) {
                        Integer count = sqfwFormsummaryNewService1.count(c);
                        if (count > 0) {
                            item.setCreateConditionFlag(true);
                        }
                    } else {
                        List<Sqfw_formSummary_new> sqfwFormSummaryNews = sqfwFormsummaryNewService1.query(c);
                        if (!sqfwFormSummaryNews.isEmpty()) {
                            int count = 0;
                            for (Sqfw_formSummary_new sfn : sqfwFormSummaryNews) {
                                SafeCheckTaskPdfDTO safeCheckTaskPdfDTO = JSONObject.parseObject(sfn.getParamData(), SafeCheckTaskPdfDTO.class);
                                //这里为了兼容老数据因此是空的情况下之前的都会生成
                                if (ObjectUtil.isEmpty(safeCheckTaskPdfDTO.getFileOutputType()) || safeCheckTaskPdfDTO.getFileOutputType().isEmpty()) {
                                    if (item.getFileIdentity().equals(String.valueOf(SafetyCheckV2Enums.G.getCode()))
                                            || item.getFileIdentity().equals(String.valueOf(SafetyCheckV2Enums.K.getCode()))) {
                                        item.setCreateConditionFlag(true);
                                    }
                                    break;
                                } else {
                                    //餐饮服务日常巡查表合集
                                    String G = String.valueOf(SafetyCheckV2Enums.G.getCode());
                                    //食品销售日常巡查表合集
                                    String K = String.valueOf(SafetyCheckV2Enums.K.getCode());

                                    if (item.getFileIdentity().contains(G) && safeCheckTaskPdfDTO.getFileOutputType().contains(G)) {
                                        item.setCreateConditionFlag(true);
                                        break;
                                    }
                                    if (item.getFileIdentity().contains(K) && safeCheckTaskPdfDTO.getFileOutputType().contains(K)) {
                                        item.setCreateConditionFlag(true);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                } else if (item.getFileIdentity().equals(CenturyCitySafeServiceEnum.CENTER_CITY_GAS_SAFE.getCode())) {
                    //燃气检测
                    Cnd c = Cnd.NEW();
                    c.and("id", "in", bean.getFormSummaryNewIdList()).and("type", "=", SupportBusinessTypeEnum.SAFE_CHECK.getName());
                    c.and("param_data ->>'type'", "=", CenturyCitySafeServiceEnum.CENTER_CITY_GAS_SAFE.getType());
                    c.orderBy("create_date", "asc");
                    List<Sqfw_formSummary_new> sqfwFormSummaryNews = sqfwFormsummaryNewService1.query(c);
                    for (Sqfw_formSummary_new sqfwItem : sqfwFormSummaryNews) {
                        SafeCheckTaskPdfDTO safeCheckTaskPdfDTO = JSONObject.parseObject(sqfwItem.getParamData(), SafeCheckTaskPdfDTO.class);
                        SafeCheckGasDTO safeCheckGasDTO = safeCheckTaskPdfDTO.getSafeCheckGasDTO();
                        if (ObjectUtils.isEmpty(safeCheckGasDTO)) {
                            continue;
                        }
                        CenturyCitySafeCheckGasUseEnum centuryCitySafeCheckGasUseEnum = CenturyCitySafeCheckGasUseEnum.getEnum(safeCheckGasDTO.getFireAndElectricityUsage());
                        if (ObjectUtils.isNotEmpty(centuryCitySafeCheckGasUseEnum)) {
                            item.setCreateConditionFlag(true);
                            break;
                        }
                    }
                } else if (item.getFileIdentity().equals(CenturyCitySafeServiceEnum.CENTER_CITY_PERSONNEL_DENSITY.getCode())
                        || item.getFileIdentity().equals(SafetyCheckV2Enums.C.getCode())) {
                    //人员密集
                    item.setCreateConditionFlag(true);

                    Cnd c = Cnd.NEW();
                    c.and("id", "in", bean.getFormSummaryNewIdList()).and("type", "=", SupportBusinessTypeEnum.SAFE_CHECK.getName());
                    c.and("param_data ->>'type'", "=", CenturyCitySafeServiceEnum.CENTER_CITY_PERSONNEL_DENSITY.getType())
                            .and("param_data->>'whetherItIsASchool'", "=", "true");
                    //zhangp 2024-05-15 人员密集食堂
                    c.orderBy("create_date", "asc");
                    List<Sqfw_formSummary_new> sqfwFormSummaryNews = sqfwFormsummaryNewService1.query(c);
                    if (item.equals(SafetyCheckV2Enums.L.getCode()) && !sqfwFormSummaryNews.isEmpty()) {
                        //食堂
                        item.setCreateConditionFlag(true);
                    }
                } else {
                    item.setCreateConditionFlag(true);
                }
                if (item.getFileIdentity().contains(CenturyCitySafeServiceEnum.CENTER_CITY_NINE_SMALL_PLACE.getCode())
                        && typeList.contains(YuHongEnum.BACK_PAY.getType())) {
                    // 欠薪风险
                    item.setCreateConditionFlag(true);
                    //break;
                }
            }
        }
        // 宾阳街道
        if (StringUtils.isNotEmpty(bean.getCounty()) && (!CommonCheckUtils.ZHISHU.equals(bean.getCounty())
                || CommonForAdminConstants.areaInfoEnum.BINYANG_STREET.getName().equals(bean.getCounty())
                || CommonForAdminConstants.areaInfoEnum.GUANSHAN_STREET.getName().equals(bean.getCounty()))) {
            LargeCompanySafeGenerator safeGenerator1 = new LargeCompanySafeGenerator();
            List<Sqfw_formSummary_new> exportData1 = safeGenerator1.getExportData(summaryNewList);
            EnterpriseSafetyInvestigationExcel safeGenerator2 = new EnterpriseSafetyInvestigationExcel();
            List<Sqfw_formSummary_new> exportData2 = safeGenerator2.getExportData(summaryNewList);
            CampusTrainingOffExcel safeGenerator3 = new CampusTrainingOffExcel();
            List<Sqfw_formSummary_new> exportData3 = safeGenerator3.getExportData(summaryNewList);
            logisticsWarehouseExcelGenerator safeGenerator4 = new logisticsWarehouseExcelGenerator();
            List<Sqfw_formSummary_new> exportData4 = safeGenerator4.getExportData(summaryNewList);
            for (BinYangFileServiceEnum item : BinYangFileServiceEnum.values()) {
                CheckDataForAdminVO checkDataForAdminVO = new CheckDataForAdminVO();
                checkDataForAdminVO = new CheckDataForAdminVO();
                checkDataForAdminVO.setType(item.getLabel());
                checkDataForAdminVO.setFileIdentity(String.valueOf(item.getCode()));
                checkDataForAdminVO.setFileName(item.getFileName() + ".xlsx");
                if (item.getFilePath().endsWith("docx")) {
                    checkDataForAdminVO.setFileName(item.getFileName() + ".pdf");
                }
                checkDataForAdminVO.setCreateConditionFlag(false);
                if (exportData1.size() > 0
                        && (item.getCode().equals(BinYangFileServiceEnum.ONE_EXCEL.getCode())
                        || item.getCode().equals(BinYangFileServiceEnum.ONE_PDF.getCode()))) {
                    checkDataForAdminVO.setCreateConditionFlag(true);
                }
                if (exportData2.size() > 0
                        && (item.getCode().equals(BinYangFileServiceEnum.TWO_EXCEL.getCode())
                        || item.getCode().equals(BinYangFileServiceEnum.TWO_PDF.getCode()))) {
                    checkDataForAdminVO.setCreateConditionFlag(true);
                }
                if (exportData3.size() > 0
                        && (item.getCode().equals(BinYangFileServiceEnum.THREE_EXCEL.getCode())
                        || item.getCode().equals(BinYangFileServiceEnum.THREE_PDF.getCode()))) {
                    checkDataForAdminVO.setCreateConditionFlag(true);
                }
                if (exportData4.size() > 0
                        && (item.getCode().equals(BinYangFileServiceEnum.FORE_EXCEL.getCode())
                        || item.getCode().equals(BinYangFileServiceEnum.FORE_PDF.getCode()))) {
                    checkDataForAdminVO.setCreateConditionFlag(true);
                }
                checkDataForAdminVOList.add(checkDataForAdminVO);
            }
        }
        // 金阳街道
        if (StringUtils.isNotEmpty(bean.getCounty()) && (!CommonCheckUtils.ZHISHU.equals(bean.getCounty())
                || CommonForAdminConstants.areaInfoEnum.JINYANG_STREET.getName().equals(bean.getCounty()))) {
            for (JinYangExcelEnum item : JinYangExcelEnum.values()) {
                CheckDataForAdminVO checkDataForAdminVO = new CheckDataForAdminVO();
                checkDataForAdminVO = new CheckDataForAdminVO();
                checkDataForAdminVO.setType(item.getType());
                checkDataForAdminVO.setLabel(Arrays.asList(JinYangExcelEnum.getLabel(String.valueOf(item.getCode())).split("\\|")));
                checkDataForAdminVO.setFileIdentity(String.valueOf(item.getCode()));
                checkDataForAdminVO.setPreviewImage(item.getPreviewImage());
                checkDataForAdminVO.setFileName(item.getFileName() + ".xlsx");
                if (item.getTemplatePath().endsWith("docx")) {
                    checkDataForAdminVO.setFileName(item.getFileName() + ".pdf");
                }
                checkDataForAdminVO.setCreateConditionFlag(false);
                int a = sqfwFormsummaryNewService1.count(Cnd.where(Sqfw_formSummary_new::getId, "IN", bean.getFormSummaryNewIdList())
                        .and(Sqfw_formSummary_new::getType, "=", bean.getType())
                        .and("param_data->>'type'", "=", JinYangExcelEnum.getType(item.getCode())));
                if (a > 0) {
                    checkDataForAdminVO.setCreateConditionFlag(true);
                }
                checkDataForAdminVOList.add(checkDataForAdminVO);
            }
        }
        return checkDataForAdminVOList;
    }

    @Override
    public void reGeneratePdf(String id) {
        centuryCitySecurityService.reGeneratePDF(id);
    }

    @Override
    protected List<ExcelGeneratorConfig> getExcelCodeGeneratorConfig(List<ExcelCreateConfig> excelConfigList, BaseExcelParamDTO baseExcelParam) {
        log.info("dayinglu excel getExcelCodeGeneratorConfig: {}", JSONObject.toJSONString(excelConfigList));
        if (excelConfigList.size() == 0) {
            return Collections.emptyList();
        }
        // 查询大营路EXCEL台账合集字典数据
        List<ExcelGeneratorConfig> list = new ArrayList<>();
        for (ExcelCreateConfig config : excelConfigList) {
            ExcelGeneratorConfig generatorConfig = new ExcelGeneratorConfig();
            generatorConfig.setExcelCreateConfig(config);
            if (YuHongEnum.BACK_PAY.getCode().equals(config.getFileIdentity())) {
                generatorConfig.setGenerator(new BackPayGenerator());
                list.add(generatorConfig);
            } else {
                BaseTemplateExcelGenerator service = CenturyCitySafeServiceEnum.getService(config.getFileIdentity());
                if (service != null) {
                    generatorConfig.setGenerator(service);
                    list.add(generatorConfig);
                }
                // 宾阳街道
                BaseTemplateExcelGenerator baseTemplateExcelGenerator = BinYangFileServiceEnum.getService(config.getFileIdentity());
                if (baseTemplateExcelGenerator != null) {
                    generatorConfig.setGenerator(baseTemplateExcelGenerator);
                    list.add(generatorConfig);
                }
                // 金阳 新增燃气使用统计表
                BaseTemplateExcelGenerator jinYangService = JinYangExcelEnum.getService(config.getFileIdentity());
                if (jinYangService != null) {
                    generatorConfig.setGenerator(jinYangService);
                    list.add(generatorConfig);
                }
            }
        }
        return list;
    }

    private void batchDeleteDataNew(String userId, Sqfw_formSummary_new data) {
        //1 记录日志
        sysLogService.insertDelLog(userId, JSONObject.toJSONString(data), Sqfw_formSummary_new.class.getAnnotation(Table.class).value(),
                "com.budwk.app.sqfw.services.customservice.DaYingLuSecurityForAdminServiceImpl.batchDeleteDataNew",
                "com.budwk.app.sqfw.controllers.admin.DaYingLuSecurityForAdminController.batchDelete");
        // 2 删除数据
        sqfwCompleteflowService.deleteAndUpdateWO(data.getSqfwFlowId());
    }

    private List<Sqfw_formSummary_new> queryBySqfwIdsAndType(List<String> summaryIds, String type) {
        Cnd cnd = Cnd.NEW();
        SqlExpressionGroup where = cnd.where();
        cnd.and(Sqfw_formSummary_new::getId, "IN", summaryIds.toArray(new String[0]));
        cnd.and(Sqfw_formSummary_new::getType, "=", type);
        cnd.getOrderBy().asc(Sqfw_formSummary_new::getFillDate);
        return sqfwFormsummaryNewService1.query(cnd);
    }

    private List<Sqfw_formSummary_new> queryJinYangGasUse(List<String> ids, String type) {
        Sys_user user = sysUserService1.getUserById(SecurityUtil.getUserId());
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(" select * from ( ");
        stringBuilder.append(" select *,row_number() over(partition by shops_base_info_id order by fill_date  desc) as num from  shequ.sqfw_form_summary_new ");
        stringBuilder.append(" where type='").append(type).append("'");
        stringBuilder.append(" and  param_data ->>'type'='九小场所'");
        if (ObjectUtils.isNotEmpty(ids)) {
            StringBuffer sb = new StringBuffer();
            for (String id : ids) {
                sb.append("'").append(id).append("',");
            }
            String idList = "";
            if (StringUtils.isNotEmpty(sb.toString())) {
                idList = sb.substring(0, sb.length() - 1);
            }
            stringBuilder.append(" and id IN (").append(idList).append(")");
        }
        stringBuilder.append(" )a where a.num=1");
        return sqfwFormsummaryNewService1.listEntity(Sqls.create(stringBuilder.toString()));
    }
}
